import { isEmpty } from './functions';
import { chooseWxImage } from './wx';


/**
 * 使用微信方式上传图片（仅限图片）
 * 包括从选择到成功的过程
 */
export function uploadWxImage (options = {}) {
  const { beforeUpload, onComplete, onError, count = 1 } = options;
  return chooseWxImage({
    count,
    beforeUpload (localFiles) {
      if (isEmpty(localFiles)) {
        return;
      }
      // 放入上传中状态
      if (beforeUpload) {
        return beforeUpload(localFiles);
      }
      return localFiles;
    },
    done (serverFiles) {
      if (isEmpty(serverFiles)) {
        return;
      }
      uploadWxServerImage(serverFiles)
        .then(files => {
          onComplete && onComplete(files);
        })
        .catch(e => {
          onError && onError(e);
        });
    }
  });
}

export function uploadWxServerImage (serverFiles) {

}
